<html>

<head>
<title>Search</title>
</head>

<body>

<h3>Search</h3>



<?php
  include 'func/search_test.func.php';
  if (isset($_POST['keywords'])) {
  $suffix = "";
  $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords']))); //
  //echo $keywords;
  $errors = array();

  if (empty($keywords)) {
	$errors[] = 'Please enter a search term';
  } else if (strlen($keywords)<3) {
	$errors[] = 'Your search term must be three or more characters';
  } else if (search_results($keywords) === false) {
	$errors[] = 'You don\'t have any image tagged by '.$strongF.' '.$keywords.' '.$strongB.'';
  }
  
  if (empty($errors)) {
    $results = search_results($keywords);
    $results_num = count($results);
    
    $suffix = ($results_num != 1) ? 's' : ''; 
    
    //echo '<pre>', print_r(search_results($keywords)), '</pre>';
    echo '<p>Your search for <strong>', $keywords, '</strong> returned <strong>', $results_num, '</strong> result', $suffix,'.</p>';
    
    foreach($results as $result) {
     
       echo $result['imageid'];
	     }
    
  
  } else {
    
    foreach($errors as $error) {
		echo $error, '</br>';
    }
  }
} 
?>
 <form action="" method="POST">
      <p>
	    <input type="text" name="keywords" /> <input type="submit" value="Search" />
      </p>
</form>	  

</body>
</html>
